var addflag = true;//操作标识
var selGroupId = 0; //当前所选联系组ID
var selMemberId = "";//当前所选联系人ID
var oldGrpName; //联系组修改前的旧组名
var contactList; //所有联系人数据

$(document).ready(function () {
	loadContact();
	loadMember(0);//显示所有
});

function loadContact() {
	var params = {};
	$.ajax({type:"POST", url:"ajaxContact_loadContact.do", data:params, async:false, success:function (result) {
		contactList = result.contactList;
		var groupHtml = "";
		for (var i = 0; i < contactList.length; i++) {
			var group = contactList[i].group;
			groupHtml += "<a href='#' onclick=\"loadMember(" + group.id + ");\">" + group.groupName + "(" + group.count + ")</a><br/>";
		}
		$("#spanGroups").html(groupHtml);
	}}, "json");
}
	
	//通过组ID取组成员信息
function getGroupMembers(groupId) {
	for (var i = 0; i < contactList.length; i++) {
		var group = contactList[i].group;
		if (group.id == groupId) {
			return contactList[i].memberList;
		}
	}
	return;
}

function getMemberById(memberId) {
	for (var i = 0; i < contactList.length; i++) {
		var memberList = contactList[i].memberList;
		for(var j=0; j <memberList.length; j++){
			if(memberId == memberList[j].id)
				return memberList[j];
		}
	}
	return;	
}

function showSelMember(bShow){
	var div_selMember=$d("div_selMember");
	if(div_selMember==null)
		return;
	else{
		if(bShow==true){
			div_selMember.style.display = "block";
		}else{
			div_selMember.style.display = "none";
		}
	}
}

	//加载联系人列表
function loadMember(groupId) {
	selMemberId = "";
	$d("div_memberlist").style.display = "block";
	$d("setpage").style.display = "block";
	showSelMember(true);
	$d("div_editgroup").style.display = "none";
	$d("div_editmember").style.display = "none";
	$d("div_viewmember").style.display = "none";
	$d("div_toolbar1").style.display = "block";
	$d("div_toolbar2").style.display = "block";
	$d("div_goBack1").style.display = "none";
	$d("div_goBack2").style.display = "none";
	selGroupId = groupId;
	if (parseInt(selGroupId) <= 0) { //0所有,-1本公司,-2未分组 时隐藏 div_group 
		$d("a_editGroup").style.display = "none";
		$d("a_deleteGroup").style.display = "none";
	} else {
		$d("a_editGroup").style.display = "block";
		$d("a_deleteGroup").style.display = "block";
	}
	$d("a_editMember").style.display = "none";
	if (selGroupId == "-1") {//公司
		$d("a_delMember").style.display = "none";
	} else {
		$d("a_delMember").style.display = "block";
	}
	var memberList = getGroupMembers(groupId);
	if (memberList.length == 0) {
		$("#tb_memberList").html("<tr><td><span class='orange1 ml5'>\u6ca1\u6709\u8054\u7cfb\u4eba\u5728\u5206\u7ec4\u4e2d</span></td></tr>");
		$d("setpage").innerHTML="";
		$d("setpage").style.display = "none";
		return;
	}
	var pageBar = NewSetPage(memberList.length,"setpage");
	var result = "<thead>";
	result += "<tr>";
	result += "<th class='title' align='center'><input id='chkAll' name='chkAll' type='checkbox' onclick=\"ChkAllClick('chkSon','chkAll')\"></th>";
	result += "<th class='title'>\u8d26\u6237\u4ee3\u7801</th>";
	result += "<th class='title'>\u8d26\u6237\u540d\u79f0</th>";
	result += "<th class='title'>\u59d3\u540d</th>";
	result += "<th class='title'>\u7535\u8bdd</th>";
	result += "<th class='title'>\u7535\u5b50\u90ae\u4ef6</th>";
	result += "</tr>";
	result += "</thead>";
	result += "<tbody>";

	//这里的order[i]就相当于list中的order,起属性也是一一对应的   
	for (var j = 0; j < memberList.length && j< pageBar.pageSize; j++) { 
		result += "<tr>";
		result += "<td align='center' width='20'><input id='" + memberList[j].id + "' name='chkSon' type='checkbox' value='" + memberList[j].id + "' onclick=\"ChkSonClick('chkSon','chkAll')\"></td>";
		result += "<td onclick=\"viewMember(" + memberList[j].id + ",'" + memberList[j].flag + "')\"><a href='#'>" + memberList[j].relateUserid + "</a></td>";
		result += "<td>" + memberList[j].relateCompanyName + "</td>";
		result += "<td>" + memberList[j].relateName + "</td>";
		result += "<td>" + memberList[j].telephone + "</td>";
		result += "<td>" + memberList[j].email + "</td>";
		result += "</tr>";
	}
	result += "</tbody>";
	$("#tb_memberList").html(result);
}

function loadPageMember(pageNum, pageSize) {
	var memberList = getGroupMembers(selGroupId);
	if (memberList.length == 0) {
		$("#tb_memberList").html("<tr><td><span class='orange1 ml5'>\u6ca1\u6709\u8054\u7cfb\u4eba\u5728\u5206\u7ec4\u4e2d</span></td></tr>");
		return;
	}
	
	var result = "<thead>";
	result += "<tr>";
	result += "<th class='title' align='center'><input id='chkAll' name='chkAll' type='checkbox' onclick=\"ChkAllClick('chkSon','chkAll')\"></th>";
	result += "<th class='title'>\u8d26\u6237\u4ee3\u7801</th>";
	result += "<th class='title'>\u8d26\u6237\u540d\u79f0</th>";
	result += "<th class='title'>\u59d3\u540d</th>";
	result += "<th class='title'>\u7535\u8bdd</th>";
	result += "<th class='title'>\u7535\u5b50\u90ae\u4ef6</th>";
	result += "</tr>";
	result += "</thead>";
	result += "<tbody>";
	//这里的order[i]就相当于list中的order,起属性也是一一对应的   
	for (var j = (pageNum-1)*pageSize; j < memberList.length && j<pageNum * pageSize; j++) { 
		result += "<tr>";
		result += "<td align='center' width='20'><input id='" + memberList[j].id + "' name='chkSon' type='checkbox' value='" + memberList[j].id + "' onclick=\"ChkSonClick('chkSon','chkAll')\"></td>";
		result += "<td onclick=\"viewMember(" + memberList[j].id + ",'" + memberList[j].flag + "')\"><a href='#'>" + memberList[j].relateUserid + "</a></td>";
		result += "<td>" + memberList[j].relateCompanyName + "</td>";
		result += "<td>" + memberList[j].relateName + "</td>";
		result += "<td>" + memberList[j].telephone + "</td>";
		result += "<td>" + memberList[j].email + "</td>";
		result += "</tr>";
	}
	result += "</tbody>";
	$("#tb_memberList").html(result);
}

function addGroup() {
	$d("div_memberlist").style.display = "none";
	$d("setpage").style.display = "none";
	showSelMember(false);
	$d("div_editgroup").style.display = "block";
	$d("div_editmember").style.display = "none";
	$d("div_viewmember").style.display = "none";
	$d("lb_editGroup").innerText = " \u65b0\u5efa\u8054\u7cfb\u4eba\u7ec4";
	showGoback();
	addflag = true;
	selGroupId = "0";
	initEditGroup();
}
function editGroup() {
	$d("div_memberlist").style.display = "none";
	$d("setpage").style.display = "none";
	showSelMember(false);
	$d("div_editgroup").style.display = "block";
	$d("div_editmember").style.display = "none";
	$d("div_viewmember").style.display = "none";
	$d("lb_editGroup").innerText = " \u7f16\u8f91\u8054\u7cfb\u4eba\u7ec4";
	showGoback();
	addflag = false;
	initEditGroup();
}
function delGroup() {
	$.prompt("\u662f\u5426\u5f7b\u5e95\u5220\u9664\u6b64\u8054\u7cfb\u7ec4\uff1f \u4ec5\u5b58\u5728\u6b64\u5206\u7ec4\u7684\u8054\u7cfb\u4eba\u4f1a\u79fb\u5230\"\u672a\u5206\u7ec4\"\u3002", {submit:delGroupCallback, buttons:{Ok:true, Cancel:false}});
}
function delGroupCallback(v, m, f) {
	if (v == true) {
		var params = {groupId:selGroupId};
		$.ajax({type:"POST", url:"ajaxContact_delGroup.do", data:params, async:false, success:function (result) {
					//alert(result.retmsg);
		}}, "json");
		loadContact();
		loadMember(0);
	}
}
function addMember() {
	$d("div_memberlist").style.display = "none";
	$d("setpage").style.display = "none";
	showSelMember(false);
	$d("div_editgroup").style.display = "none";
	$d("div_editmember").style.display = "block";
	$d("div_viewmember").style.display = "none";
	$d("lb_editMember").innerText = " \u65b0\u5efa\u8054\u7cfb\u4eba";
	$d("tr_companyName").style.display = "none";
	$d("lb_companyName").innerText = "";
	selMemberId = "";
	showGoback();
	addflag = true;
	initEditMember();
}
function editMember() {
	$d("div_memberlist").style.display = "none";
	$d("setpage").style.display = "none";
	showSelMember(false);
	$d("div_editgroup").style.display = "none";
	$d("div_editmember").style.display = "block";
	$d("div_viewmember").style.display = "none";
	$d("lb_editMember").innerText = " \u7f16\u8f91\u8054\u7cfb\u4eba";
	showGoback();
	addflag = false;
	initEditMember();
}
function viewMember(memberId, flag) {
	$d("div_memberlist").style.display = "none";
	$d("setpage").style.display = "none";
	showSelMember(false);
	$d("div_editgroup").style.display = "none";
	$d("div_editmember").style.display = "none";
	$d("a_editGroup").style.display = "none";
	$d("a_deleteGroup").style.display = "none";
	$d("div_viewmember").style.display = "block";
	$d("div_goBack2").style.display = "block";
	selMemberId = memberId;
	var params = {};
	if (flag == "1") {//公司
		$d("a_editMember").style.display = "none";
		params = {relateUserid:memberId};
	} else {
		$d("a_editMember").style.display = "block";
		params = {memberId:memberId};
	}
	$.ajax({type:"POST", url:"ajaxContact_findMember.do", data:params, async:false, success:function (result) {
		if (result.retcode == "0000") {
			var dto = result.memberInfoDto;
			spanCompanyName.innerHTML = dto.relateCompanyName;
			spanUserid.innerHTML = dto.relateUserid;
			spanUsername.innerHTML = dto.relateName;
			spanEmail.innerHTML = dto.email;
			spanTelephone.innerHTML = dto.telephone;
			if (dto.flag == "2") {
				tr_memberInfo2.style.display = "block";
				tr_memberInfo3.style.display = "block";
				spanRemark.innerHTML = dto.remark;
				var grpNames = "";
				var grpList = result.grpList;
				for (var i = 0; i < grpList.length; i++) {
					if (grpNames == "") {
						grpNames = grpList[i].groupName;
					} else {
						grpNames = grpNames + "\uff0c" + grpList[i].groupName;
					}
				}
				spanInGroups.innerHTML = grpNames;
			} else {
				tr_memberInfo2.style.display = "none";
				tr_memberInfo3.style.display = "none";
			}
		} else {
			alert("\u672a\u627e\u5230\u8054\u7cfb\u4eba\u8d44\u6599");
		}
	}}, "json");
}
function delMember() {
	var propTip = "";
	var selMemberIds = checkboxvalue("chkSon");
	if (selMemberId == "" && selMemberIds == "") {
		alert("\u8bf7\u9009\u62e9\u8981\u5220\u9664\u7684\u8054\u7cfb\u4eba");
		return;
	}
	if (parseInt(selGroupId) <= 0 || selMemberId != "") {
		propTip = "\u662f\u5426\u5f7b\u5e95\u5220\u9664\u6240\u9009\u62e9\u7684\u8054\u7cfb\u4eba\uff1f<br/><font color=\"gray\">\u8be5\u64cd\u4f5c\u5c06\u628a\u8054\u7cfb\u4eba\u4ece\u6240\u6709\u7ec4\u4e2d\u5220\u9664\u3002</font>";
	} else {
		propTip = "\u786e\u5b9a\u5c06\u9009\u4e2d\u7684\u8054\u7cfb\u4eba\u79fb\u51fa\u5f53\u524d\u7ec4\uff1f<br/><input id=\"chkDelflag\" type=\"checkbox\" /><font color=\"red\">\u5e76\u4ece\u901a\u8baf\u5f55\u4e2d\u5f7b\u5e95\u5220\u9664</font>";
	}
	$.prompt(propTip, {submit:delMemberCallback, buttons:{Ok:true, Cancel:false}});
}

function selMember() {
	var propTip = "";
	var selMemberIds = checkboxvalue("chkSon");
	if (selMemberIds == "") {
		alert("\u8BF7\u9009\u62E9\u6536\u8D27\u65B9");
		return;
	}
	var selArrIds=selMemberIds.split(",");
	if(selArrIds.length>1){
		alert("\u6709\u4E14\u53EA\u80FD\u9009\u62E9\u4E00\u4E2A\u6536\u8D27\u65B9");
		return;
	}
	var member=getMemberById(selMemberIds);
	var obj=new Array(member.relateUserid);
	window.returnValue = obj;
	window.close();
}

function delMemberCallback(v, m, f) {
	if (v == true) {
		var delflag = "0"; //是否彻底删除
		if (parseInt(selGroupId) <= 0 || selMemberId != "") {
			delflag = "1";
		} else {
			if ($("#chkDelflag").attr("checked") == true) {
				delflag = "1";
			}
		}
		var params = {};
		if (selMemberId != "") {
			params = {memberId:selMemberId, operFlag:delflag};
		} else {
	   	  	  //删除确认
			var selMemberIds = checkboxvalue("chkSon");
			params = {groupId:selGroupId, memberId:selMemberIds, operFlag:delflag};
		}
		$.ajax({type:"POST", url:"ajaxContact_delMembers.do", data:params, async:false, success:function (result) {
			alert(result.retmsg);
		}}, "json");
		loadContact();
		loadMember(selGroupId);
	}
}
function showGoback(bShow) {
	$d("div_toolbar1").style.display = "none";
	$d("div_toolbar2").style.display = "none";
	$d("div_goBack1").style.display = "block";
	$d("div_goBack2").style.display = "block";
}
function goBack() {
	loadMember(selGroupId);
}
   
   //for editGroup start ===================================
var checkGrpNameFlag = true;
function checkGroupName(txtGroupName) {
	var grpName = $.trim(txtGroupName.value);
	if (grpName == "") {
		$d("groupNameError").innerHTML = "<span class='orange1 ml5'>\u8bf7\u8f93\u5165\u7ec4\u540d</span>";
		return;
	}
		//判断编辑时组名是否更改了
	if (addflag == false && oldGrpName == grpName) {//未更改组名
		$d("groupNameError").innerHTML = "";
		return;
	}
	var operFlag = "edit";
	if (addflag == true) {
		operFlag = "add";
	}
	var params = {groupName:grpName, operFlag:operFlag, groupId:selGroupId};
	$.ajax({type:"POST", url:"ajaxContact_checkGrpNameExist.do", data:params, async:false, success:function (result) {
		if (result.retcode == "0000") {
			groupNameError.innerHTML = "<span class='orange1 ml5'>\u7ec4\u540d\u53ef\u7528</span>";
			checkGrpNameFlag = true;
		} else {
			groupNameError.innerHTML = "<span class='orange1 ml5'>\u7ec4\u540d\u5df2\u5b58\u5728</span>";
			checkGrpNameFlag = false;
		}
	}}, "json");
}
function initEditGroup() {
		//初始化listbox1
		//如果新增，listbox1为所有联系人成员，否则为不在该组的联系人成员
	var listbox1 = $d("list1");
	var listbox2 = $d("list2");
	listbox1.length = 0;
	listbox2.length = 0;
	$d("txtGroupName").value = "";
		
		//初始化可选组下拉列表 myGroup
	var params = {};
	var myGroups = $d("myGroups");
	myGroups.options.length = 0;
	var count = 0;
	for (var i = 0; i < contactList.length; i++) {
		var group = contactList[i].group;
		if (group.id != -1) {
			myGroups.options[count] = new Option(group.groupName, group.id);
			if (addflag == false && group.id == selGroupId) {
				oldGrpName = group.groupName;
				$d("txtGroupName").value = oldGrpName;
			}
			count++;
		}
	}
				
		//初始化可选联系人，已选联系人控件	
	if (addflag == true) {//新增
			//下拉显示所有联系人
		fillListbox(listbox1, getGroupMembers(0));
	} else {//如果为修改
			//初始化listbox2
		fillListbox(listbox2, getGroupMembers(selGroupId));
			//置未分组下拉项为选中状态（下拉项最后一项为未分组）
		myGroups.options[myGroups.options.length - 1].selected = true;
			
			//取未分组联系人到listbox1
		fillListbox(listbox1, getGroupMembers(-2));
			//设置未分组下拉项为选中
	}
		
		//编辑联系组控件属性绑定
		//双击
	$("#list1").dblclick(function () {
		move(listbox1, listbox2);
	});
	$("#list2").dblclick(function () {
		move(listbox2, listbox1);
	});
	    //添加
	$("#btnAdd").click(function () {
		if (listbox1.selectedIndex >= 0) {
			move(listbox1, listbox2);
		} else {
			alert("\u8bf7\u9009\u62e9\u8054\u7cfb\u4eba");
		}
	});
	    //移除
	$("#btnRemove").click(function () {
		if (listbox2.selectedIndex >= 0) {
			move(listbox2, listbox1);
		} else {
			alert("\u8bf7\u9009\u62e9\u8054\u7cfb\u4eba");
		}
	});
	    //联系组下拉改变时
	$("#myGroups").change(function () {
		var gid = this.value;
		var memberList1 = getGroupMembers(gid);
		listbox1.length = 0;
		var index = 0;
		for (var i = 0; i < memberList1.length; i++) {
			if (listbox2.options.length > 0) {
				var hasflag = false;
				for (var j = 0; j < listbox2.options.length; j++) {
					if (listbox2.options[j].value == memberList1[i].id) {
						hasflag = true;
						break;
					} else {
						continue;
					}
				}
				if (hasflag == false) {
					listbox1.options[index] = new Option(memberList1[i].relateUserid, memberList1[i].id);
					index++;
				}
			} else {
				listbox1.options[index] = new Option(memberList1[i].relateUserid, memberList1[i].id);
				index++;
			}
		}
	});
}
function saveGroup() {
	var grpName = $.trim($d("txtGroupName").value);
	if (grpName == "") {
		$d("groupNameError").innerHTML = "<span class='orange1 ml5'>\u8bf7\u8f93\u5165\u7ec4\u540d</span>";
		alert("\u7ec4\u540d\u4e0d\u80fd\u4e3a\u7a7a");
		return;
	}
	if (checkGrpNameFlag == false && oldGrpName != grpName) {
		alert("\u7ec4\u540d\u91cd\u590d\uff0c\u8bf7\u5c1d\u8bd5\u5176\u5b83\u7ec4\u540d");
		return false;
	} else {
			//保存组
		var listbox2 = $d("list2");
		/*
	        var resultArr=[];
		    for(var i=0,len=listbox2.length;i<len;i++){
		        resultArr.push(listbox2.options[i].value);
		        alert(listbox2.options[i].value);
		    }
		    */
		var resultArr = "";
		for (var i = 0, len = listbox2.length; i < len; i++) {
			resultArr = resultArr + listbox2.options[i].value + ",";
		}
		params = {groupId:selGroupId, groupName:$d("txtGroupName").value, selMembers:resultArr};
		$.ajax({type:"POST", url:"ajaxContact_saveGroup.do", data:params, async:false, success:function (result) {
			if (result.retcode = "0000") {
				loadContact();
				loadMember(result.groupId);
				alert(result.retmsg);
			} else {
				alert(result.retmsg);
			}
		}}, "json");
	}
	return true;
}
   //for editGroup end =====================================
   
   //for editMember start ==================================
function initEditMember() {
	$d("userIdError").innerHTML = "";
	$d("txtUserId").value = "";
	$d("txtUsername").value = "";
	$d("txtEmail").value = "";
	$d("txtTelephone").value = "";
	$d("txtRemark").value = "";
	var params = {};
	var result = "";
	for (var i = 0; i < contactList.length; i++) {
		var group = contactList[i].group;
		if (group.id > 0) {
			result += "<input type='checkbox' name='chk_group' id='chk_group" + group.id + "' value='" + group.id + "'/>&nbsp;";
			result += group.groupName;
			result += "<br/>";
		}
	}
	div_groups.innerHTML = result;
		//如果当前为新增操作且当前所选组不为空，则置当前所选组为选中状态
	if (selGroupId > 0 && addflag == true) {
		$d("chk_group" + selGroupId).checked = true;
	}
		
		//如果是修改，初始化已经所在组为选中状态
	if (selMemberId > 0) {
		var params = {memberId:selMemberId};
		$.ajax({type:"POST", url:"ajaxContact_findMember.do", data:params, async:false, success:function (result) {
			if (result.retcode == "0000") {
				var dto = result.memberInfoDto;
				tr_companyName.style.display = "block";
				lb_companyName.innerText = dto.relateCompanyName;
				$d("txtUserId").value = dto.relateUserid;
				$d("txtUsername").value = dto.relateName;
				$d("txtEmail").value = dto.email;
				$d("txtTelephone").value = dto.telephone;
				$d("txtRemark").value = dto.remark;
				var grpList = result.grpList;
				for (var i = 0; i < grpList.length; i++) {
					var chkbox = $d("chk_group" + grpList[i].id);
					if (chkbox != null) {
						chkbox.checked = true;
					}
				}
			} else {
				alert("\u672a\u627e\u5230\u8054\u7cfb\u4eba\u8d44\u6599");
			}
		}}, "json");
	}
}
var checkMemberFlag = true;//判断是否可用
function checkUserId(txtUserId) {
	var userIdStr = $.trim(txtUserId.value);
	if (userIdStr == "") {
		$d("userIdError").innerHTML = "<span class='orange1 ml5'>\u8bf7\u8f93\u5165\u8d26\u6237\u4ee3\u7801</span>";
		checkMemberFlag = false;
		return;
	}
	var params = {userIdVal:userIdStr};
	$.ajax({type:"POST", url:"ajaxUser_checkUserId.do", data:params, async:false, success:function (result) {
		if (result.retcode == "0001") {
			userIdError.innerHTML = "";
			tr_companyName.style.display = "block";
			lb_companyName.innerText = result.companyInfo.companyName;
			checkMemberFlag = true;
		} else {
			userIdError.innerHTML = "<span class='orange1 ml5'>" + result.retmsg + "</span>";
			tr_companyName.style.display = "none";
			lb_companyName.innerText = "";
			checkMemberFlag = false;
		}
	}}, "json");
}
function showCompanyName(txtCompanyId) {
	var companyIdVal = txtCompanyId.value;
	if (companyIdVal == "") {
		$d("companyIdError").innerHTML = "<span class='orange1 ml5'>\u8bf7\u8f93\u5165\u516c\u53f8\u4ee3\u7801</span>";
		checkMemberFlag = false;
		return;
	}
		
		//添加验证公司代码必须为正整数
	var params = {companyIdVal:companyIdVal};
	$.ajax({type:"POST", url:"ajaxUser_findCompany.do", data:params, async:false, success:function (result) {
		var companyInfo = result.companyInfo;
		if (companyInfo != null) {
			companyIdError.innerHTML = companyInfo.companyName;
			checkMemberFlag = true;
		} else {
			companyIdError.innerHTML = "<span class='orange1 ml5'>\u4e0d\u5b58\u5728\u7684\u516c\u53f8\u4ee3\u7801</span>";
			checkMemberFlag = false;
		}
	}}, "json");
}
function saveMember() {
	if ($d("txtUserId").value == "") {
		userIdError.innerHTML = "<span class='orange1 ml5'>\u8bf7\u8f93\u5165\u8d26\u6237\u4ee3\u7801</span>";
		alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u8d26\u6237\u4ee3\u7801");
		return false;
	}
	if (checkMemberFlag == false) {
		alert("\u8bf7\u8f93\u5165\u6b63\u786e\u7684\u8d26\u6237\u4ee3\u7801");
		return false;
	}
	var selGroupsVal = checkboxvalue("chk_group");
	var params = {memberId:selMemberId, relateUserid:$d("txtUserId").value, relateName:$d("txtUsername").value, email:$d("txtEmail").value, telephone:$d("txtTelephone").value, remark:$d("txtRemark").value, selGroups:selGroupsVal};
	$.ajax({type:"POST", url:"ajaxContact_saveMember.do", data:params, async:false, success:function (result) {
		if (result.retcode == "0000") {
			alert(result.retmsg);
			loadContact();
			loadMember(selGroupId);
		} else {
			alert(result.retmsg);
		}
	}}, "json");
}
   //for editMember end ====================================
   
   //====================other util func====================
function fillListbox(listbox, memberList) {
	listbox.length = 0;
	for (var i = 0; i < memberList.length; i++) {
		listbox.options[i] = new Option(memberList[i].relateUserid, memberList[i].id);
	}
}
function move(fbox, tbox) {
	for (var i = 0; i < fbox.options.length; i++) {
		if (fbox.options[i].selected && fbox.options[i].value != "") {
			var no = new Option();
			no.value = fbox.options[i].value;
			no.text = fbox.options[i].text;
			tbox.options[tbox.options.length] = no;
			fbox.options.remove(i);
			i--;
		}
	}
}
   
   // --列头全选框被单击---
function ChkAllClick(sonName, cbAllId) {
	var arrSon = document.getElementsByName(sonName);
	var cbAll = document.getElementById(cbAllId);
	var tempState = cbAll.checked;
	for (i = 0; i < arrSon.length; i++) {
		if (arrSon[i].checked != tempState) {
			arrSon[i].click();
		}
	}
}
	
	// --子项复选框被单击---
function ChkSonClick(sonName, cbAllId) {
	var arrSon = document.getElementsByName(sonName);
	var cbAll = document.getElementById(cbAllId);
	for (var i = 0; i < arrSon.length; i++) {
		if (!arrSon[i].checked) {
			cbAll.checked = false;
			return;
		}
	}
	cbAll.checked = true;
}

